<div id="main">
	<div class="hr"><hr /></div>
	<div id="example">

	<?php 
//		$admin = $_SESSION['admin'];
//		$userid = $_SESSION['userid'];
//		if (($admin == "") && ($userid == "")) {
//			echo "<h2>请先登陆</h2>";
//		}
//		else
//		{
		require 'ShopDAO.inc';
		require 'conn.php';
		$name = trim($_POST['shopname']);
		$title = trim($_POST['shoptitle']);
		$address = trim($_POST['shopaddress']);
		$telephone = trim($_POST['shopphone']);
		$email = trim($_POST['shopemail']);
		$latitude = trim($_POST['shoplatitude']);
		$longitude = trim($_POST['shoplongitude']);
		$description = trim($_POST['shopdescription']);
		$details = trim($_POST['shopdetails']);
		$type = trim($_POST['shopType']);
		$area_id = trim($_POST['area']);
		
		if (($name == "") or ($title == "") or ($address == "") or ($telephone == "") or ($email == "") or ($latitude == "") or ($longitude == "") or ($description == "")) {
				echo "<script language=javascript>alert('带*号的选项必须填写全'); history.go(-1)</script>";
				exit;
			}
			
			if (!preg_match("/(\d{3}-)(\d{8})$|(\d{4}-)(\d{7,8})$/",$telephone)&&!preg_match("/13[0-9]{9}|15[0|1|2|3|5|6|7|8|9]\d{8}|18[0|5|6|7|8|9]\d{8}/",$telephone)) 
			{
				echo "<script language=javascript>alert('错误：电话或者手机号码格式不正确'); history.go(-1)</script>";
				exit;
			}
			if (!preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i", $email)) 
			{
				echo "<script language=javascript>alert('错误：邮件格式不正确'); history.go(-1)</script>";
				exit;
			}
			
			if ($latitude<-180 or $latitude>180) 
			{
				echo "<script language=javascript>alert('错误：纬度数值不正确'); history.go(-1)</script>";
				exit;
			}
			
			if ($longitude<-180 or $longitude>180) 
			{
				echo "<script language=javascript>alert('错误：经度数值不正确'); history.go(-1)</script>";
				exit;
			}
			$sql = "SELECT name FROM shop where name='$name'";
			$result = mysql_query($sql);
	
			if ($myrow = mysql_fetch_row($result)) {
				echo("<script language=javascript>alert('已经存在该名称的店铺！'); history.go(-1)</script>");
				exit;
			}
			
			$shop = new shop();
		
			$shopid = $shop -> addshop($name, $title, $address, $telephone, $email, $latitude, $longitude, $description, $details, $type, $area_id);
			
	?>
		<br/>
		<br/>
		<h2>为该商家添加图片</h2>
		<form id="form1" method="post" enctype="multipart/form-data" action="uploadImage.php">
			<fieldset>
				<ul>
					
					<li>
						<label for="imagefile">商家图片:</label>
						
						<input id="file" type="file" name="file"">
						<input name="scan" type="hidden" id="up" value="true">
						<input type="submit" name="imagesubmit" value="上传">
						<?php 
							echo "<input name='shopid' type='hidden' value=$shopid>";
						?>
						
					</li>
				</ul>
			
			</fieldset>
		
		</form>
	<?php 
//		}
	?>		
	
	</div>
</div>